package com.wangbo.apollo.controller;

import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import com.wangbo.apollo.config.MySettings;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class TestController {
    @Value("${my.name}")
    public String name;
    @Resource
    public MySettings mySettings;

    /**
     * API
     */
    @GetMapping(value = "/api/{propertyName}")
    public String getProperty1(@PathVariable String propertyName) {
        Config namespace = ConfigService.getConfig("namespace02.yml");
        String value = namespace.getProperty(propertyName, null);
        return value;
    }

    /**
     * @Value("${xxx}")
     */
    @GetMapping(value = "/value/name")
    public String getProperty2() {
        return name;
    }

    /**
     * 注解
     */
    @GetMapping(value = "/anno")
    public String getProperty3() {
        return mySettings.toString();
    }
}
